package spark.core.scala

import org.apache.spark.{SparkContext, SparkConf}
import org.apache.spark.SparkContext._
/**
 * 統計每行出現的次數
 */
object LineCount {


  def main(args: Array[String]) {
    val conf = new SparkConf()
      .setAppName("LineCount")
      .setMaster("local")
    val sc = new SparkContext(conf)
    val lines = sc.textFile("datas/hello.txt")

    val  pairs  = lines.map(line => (line,1))
    val lineCounts = pairs.reduceByKey(_+_)
 println("----------------scala--------------------")
    lineCounts.foreach(lineCount => println(lineCount._1+" appears "+ lineCount._2))
  }
}
